package com.yh.correct.service.impl;

import java.util.List;
import java.util.Map;

import com.yh.correct.model.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yh.correct.dao.ISystemMailboxMapper;
import com.yh.correct.model.SystemMailbox;
import com.yh.correct.service.ISystemMailboxService;
/**
 * 信息站管理服务层接口实现类
 *@author崔赛赛
 *
 */
@Service
public class SystemMailboxServiceImpl implements ISystemMailboxService {
	//实例化信站箱接口
	   @Autowired
      private ISystemMailboxMapper iSystemMailboxMapper;
	@Override
	public Integer addSystemMailbox(SystemMailbox systemMailbox) {
		// 返回添加信站箱方法
		return iSystemMailboxMapper.addSystemMailbox(systemMailbox);
	}

	/**
	 * 保存信件
	 * @param systemMailbox
	 * @return
     */
	@Override
	public Integer saveMail(SystemMailbox systemMailbox) {
		return iSystemMailboxMapper.saveMail(systemMailbox);
	}

	/**
	 * 发送信件
	 * @param systemMailbox
	 * @return
     */
	@Override
	public Integer pubMail(SystemMailbox systemMailbox) {
		return iSystemMailboxMapper.pubMail(systemMailbox);
	}

	/**
	 * 通过修改发送状态发送邮件
	 * @param id
	 * @return
     */
	@Override
	public Integer pubMails(int id) {
		return iSystemMailboxMapper.pubMails(id);
	}

	@Override
	public Integer delSystemMailbox(Integer id) {
		// 返回删除信站箱方法
		return iSystemMailboxMapper.delSystemMailbox(id);
	}

	@Override
	public Integer editSystemMailbox(SystemMailbox systemMailbox) {
		// 返回编辑信站箱方法
		return iSystemMailboxMapper.editSystemMailbox(systemMailbox);
	}

	@Override
	public SystemMailbox getSystemMailbox(Integer id) {
		// 返回根据id查询信站箱方法
		return iSystemMailboxMapper.getSystemMailbox(id);
	}

	@Override
	public List<SystemMailbox> getAllSystemMailbox() {
		// 返回查询所有信站箱方法
		return iSystemMailboxMapper.getAllSystemMailbox();
	}

	/**
	 * 修改信站箱信件
	 * @param systemMailbox
	 * @return
     */
	@Override
	public int editMail(SystemMailbox systemMailbox) {
		return iSystemMailboxMapper.editMail(systemMailbox);
	}
	/**
	 * 根据发件人id查询发件箱信息
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public Page getSendIdMessage(Map<String,Object> map) throws Exception{
		Page page=new Page();
		page.setTotalNum(iSystemMailboxMapper.getSendIdMessageCount(map));
		int pageSize = Integer.parseInt(String.valueOf(map.get("pageSize")));
		page.setPageSize(pageSize);
		int curPageNum = Integer.parseInt(String.valueOf(map.get("pageNum")));
		page.setCurPageNum(curPageNum);
		page.setTotalPage(page.getTotalNum()/pageSize+(page.getTotalNum()%pageSize==0?0:1));
		page.setResult(iSystemMailboxMapper.getSendIdMessage(map));
		return page;
	}
	/**
	 * 根据收件人id查询发件箱信息
	 * @param map
	 * @return
	 * @throws Exception
	 */
	@Override
	public Page getReceiveIdMessage(Map<String, Object> map) throws Exception {
		Page page=new Page();
		page.setTotalNum(iSystemMailboxMapper.getReceiveIdMessageCount(map));
		int pageSize = Integer.parseInt(String.valueOf(map.get("pageSize")));
		page.setPageSize(pageSize);
		int curPageNum = Integer.parseInt(String.valueOf(map.get("pageNum")));
		page.setCurPageNum(curPageNum);
		page.setTotalPage(page.getTotalNum()/pageSize+(page.getTotalNum()%pageSize==0?0:1));
		page.setResult(iSystemMailboxMapper.getReceiveIdMessage(map));
		return page;
	}
	/**
	 * 根据收件人id查询收件箱未读信息条数
	 * @return
	 * @throws Exception
	 */
	@Override
	public int getUnReadMessageCount(int receiveId) throws Exception {
		return iSystemMailboxMapper.getUnReadMessageCount(receiveId);
	}

	/**
	 * 根据id将收件箱信息设为已读状态
	 * @param id
	 * @return
	 * @throws Exception
     */
	@Override
	public int readMessage(int id) throws Exception {
		return iSystemMailboxMapper.readMessage(id);
	}
	/**
	 * 批量删除信件
	 * @param list
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteBatch(List<Integer> list) throws Exception {
		return iSystemMailboxMapper.deleteBatch(list);
	}

}
